home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Supervisor's Toolkit
/
Network Supervisor's Toolkit.iso
/
users
/
ulsort
/
ulsort.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-10
|
13KB
|
344 lines
/***********************************************************************/
/* */
/* ULSORT.C */
/* */
/* Copyright (c) 1990, James M. Curran (of Ticketron) */
/* */
/***********************************************************************/
/* Created : Wednesday, March 7, 1990 at 11:13 AM */
/* */
/* Revision: 1.0 Last Revised: Friday, March 9, 1990 @ 4:49 PM */
/***********************************************************************/
/* Gives a short, constantly updated version of USERLIST, sorted */
/* by login name. Press any key to exit. */
/* */
/* Use "ULSORT ?" for complete details. */ */
/* */
/* Requires only MSC 5.1 (no external libraries) */
/* */
/* Should port to other (ANSI C) compilers with minimal trouble. */
/* */
/* Compiles "/W3 /Za" (Maximun Warning, Force ANSI compatiblity) */
/* without complaint. */
/* */
/* Passes LINT with negligible complaints. */
/* */
/***********************************************************************/
/* */
/* May be used and distributed freely (for the betterment of mankind) */
/* */
/***********************************************************************/
#include <conio.h>
#include <dos.h>
#include <search.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define DOSINT 0x21
#define DOSIDLE 0x28
#define CRTINT 0x10
#define BEEP 7
#define DELAYTIME 10
#define FALSE 0
#define TRUE (!FALSE)
/* These two structs, and the code that uses them, were stolen */
/* from a program called WHOALL.C, which I'm told was written by */
/* one "John Dilley". If you need some help with them, you're */
/* gonna have to track him down. */
struct {
int length ;
char function;
char station ;
} req ;
struct {
int length ;
char uniqueid[4] ;
int type ;
char objectname[48] ; /* Login name */
char year ; /* Year of login */
char month ; /* Month " " */
char day ; /* day " " */
char hour ; /* Hour " " */
char minute ; /* Minute" " */
char logtime[3] ;
} who ;
char *users[100];
int sort =TRUE;
int repeat=FALSE;
int top =FALSE;
/* int longm =FALSE; */
/* One day I'll impilment the LONG option */
static int sortusers(char **arg1, char **arg2);
static void Parse(int argc, char *argv[]);
/**********************************************************************/
/**********************************************************************/
void main(int argc, char *argv[])
{
union REGS r;
char *temp;
long now;
unsigned int station;
unsigned int i,j;
unsigned int height;
unsigned int OnNow;
unsigned int OnPrev=0;
/* Check the command-line parameters, and set the flags. Print */
/* instrustions if needed */
Parse(argc,argv);
do {
OnNow=0;
/* Here, we loop through all the possible stations (connections). */
for (station=1; station<100; station++) {
/* We don't want any residue from our last loop.... */
free(users[station]);
users[station]=NULL;
/* This section calls INT 21h, function E3, which gets information */
/* about the person logged on the given station. Since I stole it */
/* directly from another program, I can't go into further detail - */
/* (ie I don't know any further detail). */
r.x.ax = 0xE300 ;
r.x.si = (int) &req;
r.x.di = (int) &who;
who.length = sizeof(who) ;
req.length = sizeof(req) ;
req.function = 22 ; /* get WHO for REQed user */
req.station = (char) station ;
int86(DOSINT, &r, &r) ;
/* Here, if the given station has someone logged on, we save */
/* thier LOGIN_NAME and station #. Since it will print exactly 20 */
/* character for each person, they will display in columns 4 across.*/
if (who.objectname[0]!=0){
temp=malloc(21);
sprintf(temp," %2i-%-16s", station,who.objectname);
users[OnNow]=temp;
OnNow++;
} /* if */
/* Here we call Int 28h. DOS calls this whenever it's idle. Many */
/* TSR programs use this to avoid activating while another program */
/* is running. Be calling it directly, we are pretending that the */
/* system is idle, so these other programs can run. I did this so */
/* I could run this program and Carl Banzhof's LANUSE at the same */
/* time. */
int86(DOSIDLE, &r, &r) ;
} /* for */
/* If we asked for a sorted listing, do the sort now, using the */
/* "sortusers" (below) to determine the order. */
if (sort)
qsort(users,OnNow,sizeof(users[0]),sortusers);
/* Here, we calculate the height the listing will be. This is done */
/* by taking the number of full rows (OnNow /4, rounded down), and */
/* adding 1 if there are any partial rows. The statement */
/* "(OnNow % 4) > 0" equals 1 if the remainder is greater than zero,*/
/* 0 otherwise. (PC-Lint refers to this as "Unusual use of a */
/* Boolean" -- which it is ! */
height = (OnNow / 4) + ( (OnNow % 4) > 0);
if (repeat) {
/* If we are repeating, move cursor so we'll overwrite the last one.*/
r.h.ah=02;
r.h.bh=0;
r.x.dx= (top ? 0u : (24u-height) * 0x0100);
int86(CRTINT,&r,&r);
int86(DOSIDLE, &r, &r) ;
/* Here we compare the number of logged in users we found this time*/
/* through the loop with the number we found last time. If they */
/* differ (ie someone has logged on or off), it beeps. */
if (OnNow != OnPrev) {
putch(BEEP);
OnPrev=OnNow;
}
}
/* Print them out, in rows, going down.... */
for (i=0; i<height; i++)
for (j=0;j<4; j++)
if (users[i + j*height])
printf(users[i + j*height]);
else
printf(" ");
/* In Use, we discovered that constantly running this program will */
/* over strain the LAN (it pushed usage up to 30% by itself), so we */
/* added these short delay between cycles. The length can be */
/* adjusted by changing the #define as the top of the listing. */
/* (Sorry, it requires a recompile to change it.) */
if (repeat) {
now=time(NULL);
while (time(NULL)-now < DELAYTIME) {
int86(DOSIDLE, &r, &r) ;
if (kbhit())
break;
}
}
} while (!kbhit() && repeat);
/* At this point, the kbhit() has gotten us out of the while loop, */
/* so we remove that key from the keyboard buffer, and exit. I */
/* return the value of the key as ERRORLEVEL mainly to keep LINT */
/* happy, but I imagine one display a menu from a batch file before*/
/* starting this program, or something like that. */
if (repeat)
exit(getch()); /* clear keyboard buffer */
else
exit(0);
}
/*************************************************************************/
/* SORTUSERS */
/* o Summary: */
/* */
/* int sortusers(char **arg1, char **arg2); */
/* */
/* o Description: */
/* Comparision function for "qsort". Never called directly by this */
/* program. */
/* */
/* o Return Value: */
/* < 0 arg1 before arg2 */
/* = 0 arg1 is the same as arg2 */
/* > 0 arg1 after arg 2 */
/* 3/ 7/1990 */
/*************************************************************************/
static int sortusers(char **arg1, char **arg2)
{
return(strcmp( &((*arg1)[4]), &((*arg2)[4])));
/* That contorted line means "Compare the string pointed to by arg1 */
/* with the string pointed to by arg2, starting with a 4th character */
/* of each." */
}
/*************************************************************************/
/* PARSE */
/* o Summary: */
/* */
/* static void Parse(int argc, char *argv[]); */
/* */
/* o Description: */
/* Deal with command line parameters. */
/* */
/* o Return Value: */
/* None. Sets Global flags. */
/* 3/ 9/1990 */
/*************************************************************************/
static void Parse(int argc, char *argv[])
{
int i;
int help=FALSE;
for (i=1; i < argc; i++) {
if (strchr(strupr(argv[i]),'S') !=NULL)/* Sort alpha */
sort=TRUE;
if (strchr(argv[i],'R') !=NULL) /* Repeat */
repeat=TRUE;
if (strchr(argv[i],'T') !=NULL) /* Top */
top=TRUE;
#if 0
if (strchr(argv[i],'L') !=NULL) /* Long */
longm=TRUE;
/* One day I'll impliment the "LONG" entry option...but not today*/
#endif
if (strchr(argv[i],'U') !=NULL) /* Unsorted */
sort=FALSE;
if (strchr(argv[i],'?') !=NULL) /* Help */
help=TRUE;
}
printf("ULSORT - A sorted USERLIST");
printf(" By James M. Curran\n");
if (!help)
printf("ULSORT ? for options.\n\n");
else {
printf("Usage: ULSORT {options}\n");
printf("Options:\n");
printf(" S - Sort Alphabetically by Login Name.(Default)\n");
printf(" U - Unsorted, Listed by station number.\n\n");
printf(" R - Repeat every %d seconds until a key is pressed.\n",DELAYTIME);
printf(" T - Displays list a top of screen.\n\n");
printf(" If Repeat mode is active, list is displayed at the bottom of\n");
printf("the screen, unless the T option is specified. T has no effect\n");
printf("unless R is specified.\n\n");
printf(" Options can be given in any order, and any of the following\n");
printf("forms will work:\n");
printf("ULSORT -t -u -r ");
printf("ULSORT T U R ");
printf("ULSORT tur\n\n");
}
}
/*************************************************************************/
/* This program is provided for free, without any restrictions on it's */
/* use, distribution, modification, or cannablization. It's also */
/* provided without any warrantee whatsoever. Personally, that sounds */
/* fair to me. If you find this program interesting, or useful, or */
/* whatever, a postcard or EasyPlex saying "Golly, James, you're a */
/* wonderful programmer, and a credit to the human race" (or words to */
/* that effect) would be greatly appreciated. */
/* */
/* */
/* James M. Curran CompuServe [72261,655] */
/* 24 Greendale Road */
/* Cedar Grove, NJ 07009-1313 */
/* 3/ 9/1990 */
/*************************************************************************/